home *** CD-ROM | disk | FTP | other *** search
/ Champak 122 / Vol 122.iso / games / sketchbo.swf / scripts / DefineSprite_93_mc_immig / frame_1 / DoAction.as
Encoding:
Text File  |  2011-01-06  |  6.3 KB  |  339 lines

  1. attacking = false;
  2. speed = 0;
  3. walking = false;
  4. if(!init)
  5. {
  6.    orig_scale = _xscale;
  7.    hitarea._visible = 0;
  8.    walking = false;
  9.    parrying = false;
  10.    attacking = false;
  11.    jumping = false;
  12.    fall_distance = 0;
  13.    init = true;
  14.    side = "L";
  15.    lastdecision = 0;
  16.    deadcount = 0;
  17.    floor = 62;
  18.    walk_distance = 10;
  19.    reach = 32;
  20.    damage = 8;
  21.    total_ki = 10;
  22.    ki = total_ki;
  23.    ki_cost = 5;
  24.    pushfactor = 6;
  25.    total_hp = 50;
  26.    hp = total_hp;
  27.    regen_rate = 0.1;
  28.    score = 50;
  29.    _root.createPic("pic_immig",this);
  30. }
  31. this.onEnterFrame = function()
  32. {
  33.    if(!init)
  34.    {
  35.       return undefined;
  36.    }
  37.    if(dead)
  38.    {
  39.       deadcount++;
  40.       if(deadcount > 1000)
  41.       {
  42.          trace("unloading:" + this);
  43.          this.removeMovieClip();
  44.          unloadMovie(this);
  45.       }
  46.       gotoAndStop("die");
  47.       this._x -= _hitomi.speed;
  48.       return undefined;
  49.    }
  50.    lastdecision++;
  51.    onDie();
  52.    onWalk();
  53.    doCalcs();
  54.    var _loc3_ = fallback();
  55.    if(_loc3_ == undefined)
  56.    {
  57.       _loc3_ = 0;
  58.    }
  59.    var _loc4_ = _root.hitomi.speed;
  60.    checkHits();
  61.    decide();
  62.    this._x -= _loc4_;
  63.    this._x += _loc3_;
  64. };
  65. checkHits = function()
  66. {
  67.    if(this.hitarea.hitTest(_hitomi.hitarea))
  68.    {
  69.       onHit();
  70.    }
  71.    if(_root.hitomi.hitTest(_X + club._x * getDirection(),_Y + club._y,true))
  72.    {
  73.       _root.hitomi.recieveHit(this);
  74.    }
  75.    if(_root.hitomi.hitTest(_X + (club._x + 3) * getDirection(),_Y + club._y,true))
  76.    {
  77.       _root.hitomi.recieveHit(this);
  78.    }
  79.    if(_root.hitomi.hitTest(_X + (club._x - 3) * getDirection(),_Y + club._y,true))
  80.    {
  81.       _root.hitomi.recieveHit(this);
  82.    }
  83. };
  84. doCalcs = function()
  85. {
  86.    if(!(walking || attacking || jumping || parrying || turning || recieving))
  87.    {
  88.       ki += regen_rate;
  89.    }
  90.    if(ki > total_ki)
  91.    {
  92.       ki = total_ki;
  93.    }
  94.    if(hp > total_hp)
  95.    {
  96.       hp = total_hp;
  97.    }
  98.    if(ki < 0)
  99.    {
  100.       ki = 0;
  101.    }
  102.    if(hp < 1)
  103.    {
  104.       hp = 0;
  105.       die();
  106.    }
  107.    pic.bars.hp._xscale = Math.ceil(hp / total_hp * 100);
  108.    pic.bars.ki._xscale = Math.ceil(ki / total_ki * 100);
  109. };
  110. getDirection = function()
  111. {
  112.    if(orig_scale == _xscale)
  113.    {
  114.       return 1;
  115.    }
  116.    return -1;
  117. };
  118. bombHit = function(hit_by, dmg, pushf)
  119. {
  120.    hp -= dmg;
  121. };
  122. onHit = function()
  123. {
  124.    _root.hitcount = _root.hitcount + 1;
  125.    if(_root.hitcount > 1000)
  126.    {
  127.       _root.hitcount = 0;
  128.    }
  129.    hp -= _hitomi.damage;
  130.    _root._score += _hitomi.damage;
  131.    var _loc3_ = _root.attachMovie("mc_blood01","blood" + hitcount,6000 + hitcount);
  132.    _loc3_._rotation = random(360);
  133.    var _loc4_ = random(150) + 100;
  134.    _loc3_._xscale = _loc4_;
  135.    _loc3_._yscale = _loc4_;
  136.    if(_hitomi.side == "R")
  137.    {
  138.       _loc3_._x = _hitomi._x + _hitomi.hitarea._x;
  139.       _loc3_._y = _hitomi._y + _hitomi.hitarea._y;
  140.    }
  141.    else
  142.    {
  143.       _loc3_._x = _hitomi._x - _hitomi.hitarea._x;
  144.       _loc3_._y = _hitomi._y + _hitomi.hitarea._y;
  145.    }
  146.    fall_distance = _hitomi.pushback * 2;
  147.    fallback = function()
  148.    {
  149.       fall_distance--;
  150.       if(fall_distance < 1)
  151.       {
  152.          delete this.fallback;
  153.          fall_distance = 0;
  154.          return 0;
  155.       }
  156.       return _hitomi.getDirection() * (fall_distance / 2);
  157.    };
  158.    soundsList = ["loud_metal_hit","blow01","beat","cabasa","zddd1kick1","zddd1kick2","zddd1tamb"];
  159.    playSound(soundsList);
  160. };
  161. die = function()
  162. {
  163.    _root.removePic(pic);
  164.    dead = true;
  165.    walking = false;
  166.    slashing = false;
  167.    attacking = false;
  168.    speed = 0;
  169.    gotoAndStop("die");
  170.    play();
  171. };
  172. decide = function()
  173. {
  174.    if(dead)
  175.    {
  176.       return undefined;
  177.    }
  178.    if(!walking && !attacking || lastdecision > 75)
  179.    {
  180.       lastdecision = 0;
  181.       var _loc2_ = random(20);
  182.       if(_loc2_ == 0)
  183.       {
  184.          walk_distance = random(24) + 6;
  185.          walk();
  186.          return undefined;
  187.       }
  188.       if(_loc2_ < 3)
  189.       {
  190.          var _loc1_ = Math.abs(_hitomi._x - _X);
  191.          if(_loc1_ < 10 || _loc1_ > reach)
  192.          {
  193.             if(_hitomi._x < _X)
  194.             {
  195.                left();
  196.             }
  197.             else
  198.             {
  199.                right();
  200.             }
  201.             return undefined;
  202.          }
  203.       }
  204.       if(_loc1_ < reach)
  205.       {
  206.          if(_hitomi._x > _X && side == "L")
  207.          {
  208.             turn("R");
  209.          }
  210.          if(_hitomi._x < _X && side == "R")
  211.          {
  212.             turn("L");
  213.          }
  214.          attack();
  215.          return undefined;
  216.       }
  217.       unwalk();
  218.       gotoAndStop("stand");
  219.    }
  220. };
  221. attack = function()
  222. {
  223.    if(!attacking)
  224.    {
  225.       walking = false;
  226.       speed = 0;
  227.       attacking = true;
  228.       ki -= ki_cost;
  229.       gotoAndStop("hit");
  230.       play();
  231.    }
  232. };
  233. if(!init)
  234. {
  235.    side = "L";
  236.    orig_scale = _xscale;
  237.    init = true;
  238. }
  239. slash1 = function()
  240. {
  241.    if(jumping || slashing)
  242.    {
  243.       return undefined;
  244.    }
  245.    slashing = true;
  246.    gotoAndStop("hit");
  247.    play();
  248. };
  249. right = function()
  250. {
  251.    turn("R");
  252. };
  253. left = function()
  254. {
  255.    turn("L");
  256. };
  257. turn = function(sideto)
  258. {
  259.    if(!sideto)
  260.    {
  261.       if(side == "L")
  262.       {
  263.          sideto = "R";
  264.       }
  265.       else
  266.       {
  267.          sideto = "L";
  268.       }
  269.    }
  270.    if(side != sideto)
  271.    {
  272.       if(!jumping)
  273.       {
  274.          turnTo = sideto;
  275.          walking = false;
  276.          jumping = false;
  277.          parrying = false;
  278.          if(sideto == "L")
  279.          {
  280.             _xscale = orig_scale;
  281.          }
  282.          else
  283.          {
  284.             _xscale = - orig_scale;
  285.          }
  286.          side = sideto;
  287.       }
  288.    }
  289.    else
  290.    {
  291.       turning = false;
  292.       walk();
  293.    }
  294. };
  295. walk = function()
  296. {
  297.    if(walking || attacking || jumping || parrying || turning || dead)
  298.    {
  299.       return undefined;
  300.    }
  301.    walking = true;
  302.    gotoAndStop("walk");
  303.    play();
  304.    this.count = 0;
  305.    this.onWalk = function()
  306.    {
  307.       count++;
  308.       walking = true;
  309.       if(side == "R")
  310.       {
  311.          _X = _X + 1.5;
  312.       }
  313.       else
  314.       {
  315.          _X = _X - 1.5;
  316.       }
  317.       if(count > Math.abs(walk_distance))
  318.       {
  319.          delete this.onWalk;
  320.          walking = false;
  321.          unwalk();
  322.       }
  323.    };
  324. };
  325. unwalk = function()
  326. {
  327.    if(walking && !dead)
  328.    {
  329.       walking = false;
  330.       speed = 0;
  331.       gotoAndStop("stand");
  332.    }
  333. };
  334. playSound = function(ids)
  335. {
  336.    _root.sounds.playSound(ids);
  337. };
  338. stop();
  339.